package com.OCR.test;

import org.json.JSONArray;
import org.json.JSONObject;

class SplitTools {

    /**
     * 拆分图片识别结果
     */
    void getImageResult(JSONObject res, String fileName){
        //获取结果的Json对象
//        System.out.println("******识别结果******\n");
        JSONArray result = res.getJSONArray("words_result");
        StringBuffer sb = new StringBuffer();
        sb.append("********************分隔符**图片名称>>"+fileName+"<<**START*****************************");
        sb.append(System.lineSeparator());
        int count = 0;
        for(int i = 0; i < result.length(); i++){
            JSONObject obj = (JSONObject)result.get(i);
            count ++;
//            System.out.println("第" + count + "条结果：" + obj.getString("words"));
            String words = obj.getString("words");
            sb.append(words);
            sb.append(System.lineSeparator());
//            System.out.println(words);
        }
        sb.append("********************分隔符**END*****************************");
        sb.append(System.lineSeparator());
        Test.writeToFile(sb);
    }

    /**
     * 拆分银行卡格式
     */
    void getBankCard(JSONObject res){

        //获取识别结果
        System.out.println("******识别结果******\n");
        JSONObject obj = res.getJSONObject("result");

        //获取银行卡信息
        System.out.print("银行卡类别：");
        String name = obj.getString("bank_name");
        System.out.println(name);

        //获取银行卡号
        System.out.print("银行卡号：");
        String number = obj.getString("bank_card_number");
        System.out.println(number);
    }

    /**
     *拆分身份证格式
     */
    void getIDCard(JSONObject res){

        //获取json数据
        System.out.println("*****识别结果*****\n");
        JSONObject obj = res.getJSONObject("words_result");

        //获取姓名
        System.out.print("姓   名：");
        JSONObject name = obj.getJSONObject("姓名");
        String nameWords = name.getString("words");
        System.out.println(nameWords);

        //获取性别
        System.out.print("性   别：");
        JSONObject sex = obj.getJSONObject("性别");
        String sexWorlds = sex.getString("words");
        System.out.println(sexWorlds);

        //获取民族
        System.out.print("民   族：");
        JSONObject mz = obj.getJSONObject("民族");
        String mzWords = mz.getString("words");
        System.out.println(mzWords);

        //获取出生年月
        System.out.print("出生年月：");
        JSONObject age = obj.getJSONObject("出生");
        String ageWords = age.getString("words");
        System.out.println(ageWords);

        //获取公民身份号码
        System.out.print("身份号码：");
        JSONObject idCard = obj.getJSONObject("公民身份号码");
        String idCardWords =idCard.getString("words");
        System.out.println(idCardWords);

        //获取住址
        System.out.print("家庭住址：");
        JSONObject address = obj.getJSONObject("住址");
        String addressWords = address.getString("words");
        System.out.println(addressWords);
    }

    /**
     * 拆分银行卡格式
     */
    void getUrlImage(JSONObject res){
        System.out.println("******识别结果******\n");
        JSONArray urlWorld = res.getJSONArray("words_result");

        int count = 0;
        for(int i = 0; i < urlWorld.length(); i++){
            JSONObject json =(JSONObject)urlWorld.get(i);
            count++;
            System.out.println("Result" + count + ":" + json.getString("words"));
        }
    }
}
